/*
 * ESBlueBox.cs
 *
 * Created on December 29, 2007, 12:49 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace HexTD
{
	public class ESBlueBox : EnemySpriteBase
	{

		private int prevPaintTime;
		private Color bodyColor = new Color(255, 50, 50, 255);
#if PORT
		private Brush bodyStroke;
		private Shape[] bodyShapes;
#endif
		private int bodyStep = 0;
		private static string infoText =
				"<h1>Blue Box</h1>" +
				"<p>" +
				"It's a box, and it's blue.<br>" +
				"That means it's vulnerable to blue towers, and resistant agains yellow towers." +
				"</p>";

		/**
		 * Creates a new instance of ESBlueBox
		 */
		public ESBlueBox(Game game)
			: base(game, "Blue Box")
		{
			this.damageColor = COLOR.BLUE;
			this.damageColorAnti = COLOR.YELLOW;
		}

		public string getInfostring()
		{
			return infoText +
					"<p>" + base.getInfostring() + "</p>";
		}

		public void resetScale()
		{
#if PORT
			base.resetScale();
			Cache cache = this.context.getCache();

			if (cache.hasShapeArr("ESBBShapes" + this.size.letter)) {
				this.bodyShapes = cache.getShapeArr("ESBBShapes" + this.size.letter);
			} else {
				this.bodyShapes = new Shape[16];

				double dr = 2.0 * Math.PI / 16;
				double r = 0;
				for (int i = 0; i < this.bodyShapes.length; i++) {

					float scale = this.context.paintScale * this.size.scaleMod;
					float[,] points = {
						{+scale * (5.5f + (float) Math.Sin(+r)) / 24, +scale * (5.5f + (float) Math.Cos(+r)) / 24},
						{+scale * (5.5f + (float) Math.Cos(-r)) / 24, -scale * (5.5f + (float) Math.Sin(-r)) / 24},
						{-scale * (5.5f + (float) Math.Sin(-r)) / 24, -scale * (5.5f + (float) Math.Cos(-r)) / 24},
						{-scale * (5.5f + (float) Math.Cos(+r)) / 24, +scale * (5.5f + (float) Math.Sin(+r)) / 24}
					};
					this.bodyShapes[i] = Geometry.coordsToGeneralPath(points, true);
					r += dr;
				}
				cache.putShapeArr("ESBBShapes" + this.size.letter, this.bodyShapes);
			}
			this.bodyStroke = new Brush(2.5f * this.context.strokeScale, Brush.CAP_ROUND, Brush.JOIN_MITER);
#endif
		}

		public override void Draw(GameTime gameTime)
		{
#if PORT
			if (this.inactive || this.dead) {
				this.prevPaintTime = gameTime;
			} else {
				Brush defaultStroke = g2.getStroke();
				this.bodyStep += gameTime - this.prevPaintTime;
				if (this.bodyStep >= this.bodyShapes.Length) {
					this.bodyStep = 0;
				}
				this.prevPaintTime = gameTime;

				RotateTransform saveXform = g2.getTransform();
				g2.transform(atTranslate);

				if (this.shielded) {
					this.paintShield_bottom(g2);
				}
				this.paintHealthLine(g2);

				g2.setColor(this.bodyColor);
				g2.setStroke(this.bodyStroke);
				g2.draw(this.bodyShapes[this.bodyStep]);
				g2.setTransform(saveXform);

				if (this.shielded) {
					g2.transform(atTranslate);
					this.paintShield_top(g2);
					g2.setTransform(saveXform);
				}
			
				base.paintSelected(g2);

				g2.setStroke(defaultStroke);
			}
#endif
		}
	}
}